package com.cy.aircompressor.main.ui.lifecycle.fragment;

import android.os.Bundle;
import android.view.View;

import com.cy.aircompressor.R;
import com.cy.aircompressor.databinding.AirChildFragmentFirstBinding;
import com.cy.aircompressor.databinding.ChildContainerFragmentBinding;
import com.cy.aircompressor.main.ui.dataanalysis.fragment.child.PressureAnalysisFragment;
import com.cy.aircompressor.main.ui.dataanalysis.fragment.child.TemperatureAnalysisFragment;
import com.cy.aircompressor.main.ui.dataanalysis.fragment.child.VibrationAnalysisFragment;
import com.cy.aircompressor.main.ui.lifecycle.fragment.child.AirCompressorManagerFragment;
import com.cy.aircompressor.main.ui.lifecycle.fragment.child.ExecutiveMaintenanceFragment;
import com.cy.aircompressor.main.ui.lifecycle.fragment.child.PartsManagerFragment;
import com.cy.aircompressor.main.ui.lifecycle.fragment.child.SensorManagerFragment;
import com.cy.aircompressor.main.ui.lifecycle.viewmodel.LifeCycleViewModel;
import com.cy.aircompressor.main.view.HeaderBar;
import com.cy.aircompressor.main.view.HeaderBarTab;
import com.net.model.base.fragment.BaseVMFragment;

import java.util.ArrayList;
import java.util.List;

import me.yokeyword.fragmentation.SupportFragment;


/**
 * Created by YoKeyword on 16/6/3.
 * 信息总览
 */
public class LifeCycleFragment extends BaseVMFragment<ChildContainerFragmentBinding, LifeCycleViewModel> {

    public static LifeCycleFragment newInstance() {
        Bundle args = new Bundle();
        LifeCycleFragment fragment = new LifeCycleFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected ChildContainerFragmentBinding getViewBinding() {
        return ChildContainerFragmentBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initData() {
        initView();
        initFragments();
    }

    private List<SupportFragment> fragments = new ArrayList<>();

    private void initFragments() {
        SupportFragment firstFragment = findFragment(ExecutiveMaintenanceFragment.class);
        if (firstFragment != null) {
            // 这里库已经做了Fragment恢复,所有不需要额外的处理了, 不会出现重叠问题
            // 这里我们需要拿到mFragments的引用
            fragments.add(firstFragment);
            fragments.add(findFragment(AirCompressorManagerFragment.class));
            fragments.add(findFragment(SensorManagerFragment.class));
            fragments.add(findFragment(PartsManagerFragment.class));
        } else {
            fragments.add(ExecutiveMaintenanceFragment.newInstance());
            fragments.add(AirCompressorManagerFragment.newInstance());
            fragments.add(SensorManagerFragment.newInstance());
            fragments.add(PartsManagerFragment.newInstance());
            loadMultipleRootFragment(R.id.fl_container, 0,
                    fragments.get(0),
                    fragments.get(1),
                    fragments.get(2),
                    fragments.get(3));
        }
    }

    private void initView() {
        mBinding.bottomBar
                .addItem(new HeaderBarTab(mContext, getString(R.string.nav_zxwb)))
                .addItem(new HeaderBarTab(mContext, getString(R.string.nav_kyjgl)))
                .addItem(new HeaderBarTab(mContext, getString(R.string.nav_cgqgl)))
                .addItem(new HeaderBarTab(mContext, getString(R.string.nav_lbjgl)));
        mBinding.bottomBar.setOnTabSelectedListener(new HeaderBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int position, int prePosition) {
               showHideFragment(fragments.get(position), fragments.get(prePosition));
            }

            @Override
            public void onTabUnselected(int position) {
            }

            @Override
            public void onTabReselected(int position) {
            }
        });
        mBinding.airCompressorView.setVisibility(View.GONE);
    }

    @Override
    protected void requestNetwork() {

    }


    @Override
    protected void dataChange() {

    }
}
